<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <div class="search">
      <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-form-item label="区域搜索:">
          <el-input v-model="form.name" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="searchOrderFn"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 信息列表区域 -->
    <div class="result">
      <el-button class="btn" icon="el-icon-circle-plus" @click="addOrderFn"
        >新建</el-button
      >
      <!-- table表格区域 -->
      <el-table :data="tableData" style="width: 100%" :highlight-current-row="true"
        :cell-style="{padding: '5px'}">
        <el-table-column type="index" :index="indexFn" label="序号" width="80">
        </el-table-column>
        <el-table-column prop="name" label="区域名称"> </el-table-column>
        <el-table-column prop="nodeCount" label="点位数"> </el-table-column>
        <el-table-column prop="remark" label="备注说明"></el-table-column>
        <el-table-column label="操作" width="200">
          <template v-slot="{ row }">
            <el-button type="text" size="medium" @click="lookInfoFn(row)">查看详情</el-button>
            <el-button type="text" size="medium" @click="edit(row)">修改</el-button>
            <el-button type="text" style="color:red" size="medium" @click="delArea(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
        <div class="footbtn">
          <div class="page">
            <span> 共 {{totalCount}}条记录 第{{pageParams.pageIndex}}/{{ totalPage }}页</span>
          </div>
        <!-- 分页按钮 -->
          <el-row type="flex" justify="end">
          <el-pagination
          layout="prev, next"
          prev-text="上一页"
          :current-page.sync="pageParams.pageIndex"
          @current-change="changeFn"
          next-text="下一页"
          :total="+totalCount">
        </el-pagination>
          </el-row>
        </div>
    </div>
    <!-- 新建、修改 弹层 -->
    <AddArea :addAreaDialog.sync="addAreaDialog"
    :tableData="tableData" :editRow="editRow"
    ref="addEdit"
    />
    <!-- 查看详情弹层 -->
    <el-dialog :visible.sync="showDetailDialog" title="区域详情" width="630px">
      <el-form>
        <el-form-item label="区域名称:" style="margin-left: 70px">
          <el-row>
            城北街道
          </el-row>
        </el-form-item>
        <el-row type="flex">
          <el-form-item label="包含点位:" style="margin-left: 70px">
            </el-form-item>
          <el-table
          class="table"
            :data="tableDetail"
            stripe>
            <el-table-column
            width="80"
            type="index"
            :index="indexFn"
              prop="date"
              label="序号">
            </el-table-column>
            <el-table-column
             width="158"
              prop="name"
              label="点位名称">
            </el-table-column>
            <el-table-column
            width="158"
              prop="vmCount"
              label="设备数量">
            </el-table-column>
          </el-table>

        </el-row>
      </el-form>

    </el-dialog>
  </div>
</template>

<script>
import { getAreaList, delArea, searchArea, nodeSearch } from '@/api/place'
import AddArea from './components/AddArea'
export default {
  components: {
    AddArea
  },
  data () {
    return {
      tableDetail: [], // 查看详情
      showDetailDialog: false, // 控制查看详情弹层显示
      editRow: null, // 编辑时传到子组件的当前数据
      addAreaDialog: false, // 新增区域弹层显示
      pageParams: {
        pageIndex: 1,
        pageSize: 10
      },
      totalPage: 0, // 总页数
      totalCount: 0, // 总条数
      form: {
        name: '' // 搜索内容
      },
      tableData: [] // 区域列表数据
    }
  },
  created () {
    this.getAreaList()
  },
  methods: {
    // 修改区域
    edit (row) {
      this.editRow = row
      this.addAreaDialog = true
      this.$refs.addEdit.edit()
    },
    // 删除区域
    async delArea (id) {
      await delArea(id)
      this.$message.success('删除成功！')
      if (this.tableData.length === 1) {
        this.pageParams.pageIndex--
      }
      this.getAreaList()
    },
    changeFn () {
      this.getAreaList()
    },
    // 获取区域列表
    async getAreaList () {
      const res = await getAreaList({ ...this.pageParams })
      this.tableData = res.data.currentPageRecords
      this.totalPage = res.data.totalPage
      this.totalCount = res.data.totalCount
    },
    // 搜索
    async searchOrderFn () {
      const res = await searchArea({
        ...this.pageParams, ...this.form
      })
      this.tableData = res.data.currentPageRecords
    },
    // 新增区域
    addOrderFn () {
      this.addAreaDialog = true
      this.editRow = null
    },
    // 表格序号
    indexFn (index) {
      return index + this.pageParams.pageSize * (this.pageParams.pageIndex - 1) + 1
    },
    // 查看详情
    async lookInfoFn (row) {
      const res = await nodeSearch({ ...this.pageParams, regionId: row.id })
      this.tableDetail = res.data.currentPageRecords
      this.showDetailDialog = true
    }
  }
}
</script>

<style lang="less" scoped>
.app-container {
  padding: 15px;
  .search {
    display: flex;
    height: 64px;
    align-items: center;
    padding-left: 17px;
    background-color: #fff;
    .demo-form-inline {
      margin-top: 21px;
    }
  }
  .result {
    margin-top: 20px;
    padding: 15px;
    background-color: #fff;
    .btn {
      background-color: #ff893a;
      color: #fff;
    }
     .table{
        padding: 20px 15px 19px 17px;
        background-color: #fff;
      }
      .footbtn{
        margin-top: 20px;
        display: flex;
        justify-content: space-between;
      }
  }
}
.primary1{
  margin-left: 40px !important;
  background-color: #ff722c;
  color: #fff;
}
.page{
    span{
    display: inline-block;
    font-size: 16px;
    color: #e5e2e5;
    min-width: 35.5px;
    height: 28px;
    line-height: 28px;
    vertical-align: top;
    box-sizing: border-box;
    }
}
/deep/ .btn-prev,/deep/.btn-next{
  span{
  display: inline-block;
  width: 70px;
  height: 32px;
  border-radius: 2px;
  background-color: #d5ddf8;
  }
}
/deep/.el-dialog {
  border-radius: 10px;
}
// /deep/ .el-table__cell{
//   line-height: 44px;
//   padding: 0;
//   margin: 0;
// }
.table{
  transform: translateY(-3px);
}
</style>
